//
//  GetAlertListApi.m
//  RONGAO
//
//  Created by Kendama on 2018/3/1.
//  Copyright © 2018年 wei wang. All rights reserved.
//

#import "GetAlertListApi.h"
#import "AlertModel.h"

@implementation GetAlertListApi
{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/ronggao/Door_lock_device/get_alert_list";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];
    
    [dic setValuesForKeysWithDictionary:_dic];
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
}


-(void)dealloc
{
    NSLog(@"%@ dealloc",[self class]);
}

+(void)getAlertListWithDeviceMac:(NSString *)deviceMac page:(int)page success:(void (^)(NSArray<AlertModel *> *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:@(page).stringValue forKey:@"page"];
    [requestDic setValue:deviceMac forKey:@"device_mac"];
    
    GetAlertListApi *api = [[GetAlertListApi alloc] initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        NSMutableArray *childList = [[NSMutableArray alloc]init];
        NSDictionary *dic = request.responseObject;
        if (dic[@"data"] && [dic[@"data"] isKindOfClass:[NSArray class]]) {
            NSArray *list = dic[@"data"];
            for (NSDictionary *infoDic in list) {
                AlertModel *model = [[AlertModel alloc]init];
                [model setValuesForKeysWithDictionary:infoDic];
                [childList addObject:model];
            }
        }
        if (successBack) {
            successBack(childList);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
    
}

@end
